package cn.ljn.basic.service.impl;

import cn.ljn.basic.eum.ShopStateEnum;
import cn.ljn.basic.service.EchartService;
import cn.ljn.basic.vo.EchartVo;
import cn.ljn.org.mapper.ShopMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class EchartServiceImpl implements EchartService {

    @Autowired
    private ShopMapper shopMapper;

    @Override
    public Map<String, Object> echart() {
        Map<String, Object> result = new HashMap<>();
        // 查询店铺各个状态以及状态的数量
       List<EchartVo> shopList =  shopMapper.echart();
        // 获取到状态集合
//        List<Integer> states = shopList.stream().map(EchartVo::getState).collect(Collectors.toList());
        List<String> states = shopList.stream().map(vo -> ShopStateEnum.getNameByCode(vo.getState())).collect(Collectors.toList());

        // 获取到数量集合
        List<Integer> counts = shopList.stream().map(EchartVo::getCount).collect(Collectors.toList());
        result.put("x",states);
        result.put("y",counts);
        return result;
    }
}
